<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
   
</head>
<body>
<button onclick="openFile()">选择文件</button>
<button onclick="cutAsPreview()">剪切并预览</button>
<button onclick="cutAsGet()">剪切并获取</button>

<div id="mypreview" style="width:1000px; height:1000px; margin-top:100px; margin-left:100px;">


</div>

<div id="preview"></div>


</body>

<script type="text/javascript" src="./ViewUploader.js"></script>
<script type="text/javascript">
    //创建文件框并选择文件
    
    var viewUploader = new ViewUploader({container: document.getElementById("mypreview")});
    var first = true;
    function openFile(){
        if(!first){
            viewUploader.clear();
        }
        first = false;

        viewUploader.selectFile();
    }

    function cutAsGet(){
        console.log(viewUploader.cutAsBase64());
    }

    function cutAsPreview(){
        viewUploader.cutAsView(document.getElementById("preview"));
    }
</script>

</html>